<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../../vue.js"></script>
</head>

<body>
  <div id="app">
    {{mail}}
    <custom-mail v-model="mail"></custom-mail>
  </div>


  <script>

    Vue.component('custom-mail', {
      template: `
    <input type="text"
@input="handleInput($event)"
    />
    `,
      methods: {
        validateMail(mail) {
          //abc@163.com
          return /^\w{3,15}\@\w+\.[a-z]{2,3}$/.test(mail);
        },
        handleInput(event) {
          let mail = event.target.value;
          if (this.validateMail(mail)) {
            this.$emit('input', mail)
          } else {
            this.$emit('input', '')
          }
        }
      }
    })


    var vm = new Vue({
      el: "#app",
      data: {
        mail: ''
      }
    })

  </script>

</body>

</html>